<?php
	if ($mod=="group"){
		if ($act == 'add') {
			$clientsclass->group_add($parent, $name);
		} elseif ($act == 'del_mas') {
			$del_mas = array();
			if (isset($_GET["ids"])) $del_mas=$_GET["ids"];
			elseif (isset($_POST["ids"])) $del_mas=$_POST["ids"];
			if (count($del_mas) > 0){
				$clientsclass->group_del($del_mas);
			}
		} elseif ($act == 'mod') {
			if (isset($_POST["name"]) && isset($_POST["group_id"])){
				$clientsclass->group_mod($_POST["group_id"], $_POST["name"]);
			}
		}
	} elseif ($mod=="client"){
		if ($act == 'add_fields') {
			if (isset($_POST["form_id"]) && isset($_POST["form_id"]) && isset($_POST["client_id"]) && (strlen($_POST["client_id"]) > 0)){
				$clientsclass->add_fields_to_client($_POST["client_id"], $_POST["form_id"]);
			}
		} elseif ($act == 'add_to_groups') {
			$clientsclass->del_client_from_all_group($login_id);
			if (isset($_POST['group_array'])){
				foreach ($_POST['group_array'] as $key=>$value){
					if ($value == "on")	$clientsclass->add_client_to_group($login_id, $key);
				}
			}
		} elseif ($act == 'add_to_groups_array') {
			$del_mas = array();
			if (isset($_POST["ids"])) $del_mas=$_POST["ids"];
			if (count($del_mas) > 0){
				foreach ($del_mas as $k=>$v){
					$clientsclass->del_client_from_all_group($k);
					if (isset($_POST['group_array'])){
						foreach ($_POST['group_array'] as $key=>$value){
							if ($value == "on")	$clientsclass->add_client_to_group($k, $key);
						}
					}
				}
			}
		} elseif ($act == 'del_mas') {
			$del_mas = array();
			if (isset($_GET["ids"])) $del_mas=$_GET["ids"];
			elseif (isset($_POST["ids"])) $del_mas=$_POST["ids"];
			if (count($del_mas) > 0){
				$clientsclass->clients_del($del_mas);
			}
		} elseif ($act == 'add') {
			$data = array();
			if (isset($_POST["email"])) $login_data['email']=$_POST["email"];
			if (isset($_POST["group_id"]) && (strlen($_POST["group_id"]) > 0)) $login_data['group']=$_POST["group_id"];
			if (isset($_POST["form_id"]) && (strlen($_POST["form_id"]) > 0)) {
				$tmp = $treeclass->get_item_content($_POST["form_id"]);
				/*
				if (isset($tmp['id_login'])) $login_data['login'] = "";
				if (isset($tmp['id_pass'])) $login_data['pass1'] = "";
				if (isset($tmp['id_pass'])) $login_data['pass2'] = "";
				*/
				$login_data['pass2'] = $login_data['pass1'] = $login_data['login'] = "";
				$tmp = $tmp['block_client_form_data']['value'];
				foreach ($tmp as $key=>$val){
					if ((isset($val['label'])) && (isset($val['type']))){
						$data['form_data_'.$key]['label'] = $val['label'];
						$data['form_data_'.$key]['type'] = $val['type'];
						$data['form_data_'.$key]['value'] = "";
					}
				}
			}
			if (isset($login_data['email'])) $res = $clientsclass->add_new_registation($login_data, $data, 1, $_POST["form_id"]);
			if ($res != 0) $err->AddError($res);
			unset($tmp);
		} elseif ($act == 'mod') {
			if (isset($_POST["client_id"]) && (strlen($_POST["client_id"]) > 0)){
				foreach($_POST as $key=>$el){
					if ((strpos($key, "client_data_") !== false) and (strpos($key, "client_data_") == 0)){
						$key = substr($key, strlen("client_data_"));
						$client_data[$key] = $el;
					}
				}
				foreach($_FILES as $key=>$el){
					if ((strpos($key, "client_data_") !== false) and (strpos($key, "client_data_") == 0)){
						$key = substr($key, strlen("client_data_"));
						$client_data[$key] = $el;
					}
				}

				$res = $clientsclass->mod_user_registation_data($_POST["client_id"], $client_data);
				if ($res != 1) $err->AddError($res);
			}
		}  elseif ($act == 'assign_group_permission') {
			if (isset($_POST["parent"]) && (strlen($_POST["parent"]) > 0)){
				$ids = array();
				if (isset($_POST["ids"])) $ids = $_POST["ids"];
				$clientsclass->assign_group_permission($_POST["parent"], $ids);
			}
		} elseif ($act == 'export_client_emails') {
			$clientsclass->emails_export();
		}
	} elseif ($mod=="files"){
		if ($act == 'del') {
			$clientsclass->file_del_with_parent_data($parent, $field_name, $image_id);
		}
	} elseif ($mod=="search"){
		$clients = array();
		if (!isset($_GET['query'])) $query=NULL; else $query=$_GET['query'];
		if ($query==NULL) if (!isset($_POST['query'])) $query=NULL; else $query=$_POST['query'];
		if ($query!=NULL) $clients = $clientsclass->get_clients_by_search($query);
		$data['clients_search'] = $clients;
	} elseif ($mod=="pass_letter"){
		$letters_text_before = ""; $letters_text_after = ""; $letters_subject = ""; $letters_from = "";
		if (isset($_POST["letters_text_before"]) && (strlen($_POST["letters_text_before"])> 0)) $letters_text_before = $_POST["letters_text_before"];
		if (isset($_POST["letters_text_after"]) && (strlen($_POST["letters_text_after"])> 0)) $letters_text_after = $_POST["letters_text_after"];
		if (isset($_POST["letters_subject"]) && (strlen($_POST["letters_subject"])> 0)) $letters_subject = $_POST["letters_subject"];
		if (isset($_POST["letters_from"]) && (strlen($_POST["letters_from"])> 0)) $letters_from = $_POST["letters_from"];

		if (isset($_POST["clang"]) && (strlen($_POST["clang"])> 0)) $clang = $_POST["clang"];
		else $clang = $setupdata['default_languages'];
		
		$clientsclass->mod_pass_letter_data($letters_from, $letters_subject, $letters_text_before, $letters_text_after, $clang);
	}
?>